package com.glsc.ngateway.common.base.repo.mysql.cmdb;

import com.glsc.ngateway.common.base.domain.mysql.cmdb.CmdbMachineCabinetU;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
public interface CmdbMachineCabinetURepository extends JpaRepository<CmdbMachineCabinetU, Integer>, JpaSpecificationExecutor<CmdbMachineCabinetU> {
    @Query(value = "select m from CmdbMachineCabinetU m where m.isDelete=0 " +
//            "and (:#{#paramSearchDto.shareHolderAccount} is null OR m.shareHolderAccount = :#{#paramSearchDto.shareHolderAccount})  " +
//            "and (:#{#paramSearchDto.shareHolderAccountName} is null OR m.shareHolderAccountName = :#{#paramSearchDto.shareHolderAccountName})  " +
//            "and (:#{#paramSearchDto.shareHolderAccountName} is null OR m.shareHolderAccountName = :#{#paramSearchDto.shareHolderAccountName})  " +
//            "and (:#{#paramSearchDto.futureCompany} is null OR m.futureCompany LIKE CONCAT('%',:#{#paramSearchDto.futureCompany},'%') )  " +
            "and (:#{#paramSearchDto.machineCabinetUCode} is null OR m.machineCabinetUCode LIKE CONCAT('%',:#{#paramSearchDto.machineCabinetUCode},'%') )  " +
            "and (:#{#paramSearchDto.machineCabinetCode} is null OR m.machineCabinetCode LIKE CONCAT('%',:#{#paramSearchDto.machineCabinetCode},'%') )  " +
            "and (:#{#paramSearchDto.uStart} is null OR m.uStart = :#{#paramSearchDto.uStart})  " +
            "and (:#{#paramSearchDto.uEnd} is null OR m.uEnd = :#{#paramSearchDto.uEnd})  " +
            "and (:#{#paramSearchDto.isOnly} is null OR m.isOnly = :#{#paramSearchDto.isOnly})  " +
            "and (:#{#paramSearchDto.installType} is null OR m.installType = :#{#paramSearchDto.installType})  " +
//            "and (:#{#paramSearchDto.shareHolderAccountName} is null OR m.shareHolderAccountName LIKE CONCAT('%',:#{#paramSearchDto.shareHolderAccountName},'%') )  " +
//            "and (:#{#paramSearchDto.market} is null OR m.market = :#{#paramSearchDto.market})  " +
//            "and (:#{#paramSearchDto.status} is null OR m.status = :#{#paramSearchDto.status})  " +
//            "and (:#{#paramSearchDto.shareHolderUseDepartment} is null OR m.shareHolderUseDepartment = :#{#paramSearchDto.shareHolderUseDepartment})  " +
//            "and (:#{#paramSearchDto.belongDeptId} is null OR m.belongDeptId = :#{#paramSearchDto.belongDeptId})  " +
//            "and (:#{#paramSearchDto.opSupportName} is null OR m.opSupportName LIKE CONCAT('%',:#{#paramSearchDto.opSupportName},'%') )  " +
//            "and (:#{#paramSearchDto.systemSummary} is null OR m.systemSummary LIKE CONCAT('%',:#{#paramSearchDto.systemSummary},'%') )  " +
//            "and (:#{#paramSearchDto.processDefineKey} is null OR m.processDefineKey = :#{#paramSearchDto.processDefineKey} )  " +
//            "and (:#{#paramSearchDto.systemCode} is null OR m.systemCode = :#{#paramSearchDto.systemCode} )  " +
//            "and (:#{#paramSearchDto.beginDateLocalDate} is null OR m.processCreateTime >= :#{#paramSearchDto.beginDateLocalDate} )  " +
//            "and (:#{#paramSearchDto.endDateLocalDate} is null OR m.processCreateTime <= :#{#paramSearchDto.endDateLocalDate} )  " +
//            "and (:#{#paramSearchDto.hasProcessEnd} is null OR m.isClose = :#{#paramSearchDto.hasProcessEnd} )  " +
//            "and (coalesce(:#{#paramSearchDto.adminList}, null) is null or m.systemAdminAccount in (:#{#paramSearchDto.adminList})) " +
            "")
    Page<CmdbMachineCabinetU> searchByParam(Pageable pageable, CmdbMachineCabinetU paramSearchDto);

    List<CmdbMachineCabinetU> findAllByIdIn(List<Long> id);

    @Transactional
    @Modifying
    @Query(value = "update t_cmdb_machine_cabinet_u set is_delete = :deleted where machine_cabinet_u_code in :codes ", nativeQuery = true)
    void updateIsDeleteByCodes(Integer deleted, List<String> codes);
}



